package com.hjl.service.pojo;

import com.hjl.dao.pojo.PojoMapper;
import com.hjl.entity.Pojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/*@Transactional*/
@Scope("prototype")
@Service("pojoService")
public class PojoServiceImpl implements PojoService {

    @Autowired // 或 @Resource
    private PojoMapper pojoMapper;

/*    public PojoMapper getPojoMapper() {
        return pojoMapper;
    }*/

/*    public void setPojoMapper(PojoMapper pojoMapper) {
        this.pojoMapper = pojoMapper;
    }*/

    @Override
    /*@Transactional(propagation = Propagation.SUPPORTS)*/
    public List<Pojo> findUsersWithConditions(Pojo pojo) {

        try {
            return pojoMapper.getUserList(pojo);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public boolean addNewPojo(Pojo pojo) {

        boolean result = false;

        try {
            if (pojoMapper.add(pojo) == 1) {
                result = true;
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }

        return result;
    }

    @Override
    public int updateInfos(Pojo pojo) {

        try {
            int result = pojoMapper.updateInfoById(pojo);
            return result;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int deleteInfo(Integer id) {

        try {
            int result = pojoMapper.deleteInfo(id);
            return result;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }
    @Override
    public int updatePwdById(String userPassword ,int id) {

        try {
            return pojoMapper.updatePwdById(userPassword,id);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }


}
